/**
 * @file lnm8f01.h
 * @brief 
 * @version 0.1
 * @date 2023-09-12
 * 
 */

#ifndef __LNM8F01_H__
#define __LNM8F01_H__

sfr SP       = 0x81;
sfr DPL      = 0x82;
sfr DPH      = 0x83;
sfr PCON     = 0x87;
sfr INTF0    = 0x88;
sfr T0CON    = 0x89;
sfr T0CNT    = 0x8A;
sfr T1CON    = 0x8C;
sfr T1CNTL   = 0x8D;
sfr T1CNTH   = 0x8E;
sfr SDR      = 0x8F;

sfr PADATA   =  0x90 ;
sbit PA0DATA = PADATA^0;
sbit PA1DATA = PADATA^1;
sbit PA2DATA = PADATA^2;
sbit PA3DATA = PADATA^3;
sbit PA4DATA = PADATA^4;
sbit PA5DATA = PADATA^5;
sbit PA6DATA = PADATA^6;
sbit PA7DATA = PADATA^7;

sfr U0TXCR   = 0x91;
sfr U0TXREG  = 0x92;
sfr U0RXCR   = 0x93;
sfr U0RXREG  = 0x94;
sfr U0BRGDH  = 0x95;
sfr U0BRGDL  = 0x96;
sfr U0INTF0  = 0x97;

sfr PBDATA   =  0x98 ;
sbit PB0DATA = PBDATA^0;
sbit PB1DATA = PBDATA^1;
sbit PB2DATA = PBDATA^2;
sbit PB3DATA = PBDATA^3;
sbit PB4DATA = PBDATA^4;
sbit PB5DATA = PBDATA^5;

sfr U0INTCR0 = 0x99;
sfr U1TXCR   = 0x9B;
sfr U1TXREG  = 0x9C;
sfr U1RXCR   = 0x9D;
sfr U1RXREG  = 0x9E;
sfr U1BRGDH  = 0x9F;
sfr P2       = 0xA0;
sfr U1BRGDL  = 0xA1;
sfr U1INTF0  = 0xA2;
sfr U1INTCR0 = 0xA3;
sfr WDTCON0  = 0xA4;
sfr WDTCON1  = 0xA5;
sfr WDTCLR   = 0xA6;
sfr IEN0     = 0xA8;
sfr I2CDAT   = 0xA9;
sfr I2CADR   = 0xAA;
sfr I2CCON   = 0xAB;
sfr I2CSTA   = 0xAC;

sfr PCDATA   =  0xB0 ;
sbit PC0DATA = PCDATA^0;
sbit PC1DATA = PCDATA^1;
sbit PC2DATA = PCDATA^2;
sbit PC3DATA = PCDATA^3;
sbit PC6DATA = PCDATA^6;
sbit PC7DATA = PCDATA^7;

sfr SPSTA    = 0xB1;
sfr SPCON    = 0xB2;
sfr SPDAT    = 0xB3;
sfr SPSSN    = 0xB4;
sfr IPL0     = 0xB8;

sfr PDDATA   =  0xC0 ;
sbit PD0DATA = PDDATA^0;
sbit PD1DATA = PDDATA^1;
sbit PD2DATA = PDDATA^2;
sbit PD3DATA = PDDATA^3;
sbit PD4DATA = PDDATA^4;
sbit PD5DATA = PDDATA^5;

sfr PAOE     =  0xC8 ;
sfr PSW      =  0xD0 ;
sfr PBOE     =  0xD8 ;
sfr ACC      =  0xE0 ;
sfr IEN1     =  0xE6 ;
sfr IEN2     =  0xE7 ;
sfr PCOE     =  0xE8 ;
sfr B        =  0xF0 ;
sfr INTF1    =  0xF1 ;
sfr INTF2    =  0xF2 ;
sfr IPL2     =  0xF4 ;
sfr IPL1     =  0xF6 ;
sfr IMOD0    =  0xF7 ;
sfr PDOE     =  0xF8 ;

// BIT Register
// PSW
sbit CY      = 0xD7;
sbit AC      = 0xD6;
sbit F0      = 0xD5;
sbit RS1     = 0xD4;
sbit RS0     = 0xD3;
sbit OV      = 0xD2;
sbit P       = 0xD0;

// IEN0
sbit EA      = 0xAF;
sbit SCCBMCIE = 0xAE;
sbit CCBMCIE = 0xAD;
sbit CMP1IE  = 0xAC;
sbit CMP0IE  = 0xAB;
sbit EXT1IE  = 0xAA;
sbit LVDIE   = 0xA9;
sbit EXT0IE  = 0xA8;

// IPL0
sbit EXT0IP  = 0xB8;
sbit LVDIP   = 0xB9;
sbit EXT1IP  = 0xBA;
sbit CMP0IP  = 0xBB;
sbit CMP1IP  = 0xBC;
sbit CCBMCIP = 0xBD;
sbit SCCBMCIP = 0xBE;

// INTF0
sbit EXT0IF  = 0x88;
sbit LVDIF   = 0x89;
sbit EXT1IF  = 0x8A;
sbit CMP0IF  = 0x8B;
sbit CMP1IF  = 0x8C;
sbit CCBMCIF = 0x8D;
sbit SCCBMCIF = 0x8E;

/* Interrupt numbers: address = (number * 8) + 3 */
#define EXT0_IRQ      0
#define LVD_IRQ       1
#define EXT1_IRQ      2
#define CMP0_IRQ      3
#define CMP1_IRQ      4
#define CCBMC_IRQ     5
#define CCBMCS_IRQ    6
#define WDT_IRQ       7
#define T0_IRQ        8
#define T1_IRQ        9
#define T2_IRQ        10
#define T3_IRQ        11
#define T4_IRQ        12
#define PWM_IRQ       13
#define UART0_IRQ     14
#define UART1_IRQ     15
#define SPI_IRQ       16
#define I2C_IRQ       17
#define ADC_IRQ       18
#define PA_IRQ        19
#define PB_IRQ        20
#define PC_IRQ        21
#define PD_IRQ        22
#define LED0_IRQ      23
#define LED1_IRQ      24

// xfr
extern volatile unsigned char xdata OSCCK;
extern volatile unsigned char xdata PLLCK;
extern volatile unsigned char xdata PLLN;
extern volatile unsigned char xdata PLLM;
extern volatile unsigned char xdata SYSCK;
extern volatile unsigned char xdata WDTCK;
extern volatile unsigned char xdata TM0CK;
extern volatile unsigned char xdata TM1CK;
extern volatile unsigned char xdata TM2CK;
extern volatile unsigned char xdata TM3CK;
extern volatile unsigned char xdata TM4CK;
extern volatile unsigned char xdata PWMCK;
extern volatile unsigned char xdata ADCCK;
extern volatile unsigned char xdata SOFTRST;
extern volatile unsigned char xdata VREFCR;
extern volatile unsigned char xdata OPA0CR;
extern volatile unsigned char xdata CMP0CR;
extern volatile unsigned char xdata CMP1CR;
extern volatile unsigned char xdata LVDCR;
extern volatile unsigned char xdata TEMPCR;
extern volatile unsigned char xdata LDOCR;
extern volatile unsigned char xdata VDETCR;
extern volatile unsigned char xdata DAC0CR;
extern volatile unsigned char xdata DAC1CR;
extern volatile unsigned char xdata CMPTRICR;
extern volatile unsigned char xdata KEY;
extern volatile unsigned char xdata UNLOCK;
extern volatile unsigned char xdata TIMING;
extern volatile unsigned char xdata ARL;
extern volatile unsigned char xdata ARH;
extern volatile unsigned char xdata WDATA;
extern volatile unsigned char xdata CMD;
extern volatile unsigned char xdata BUSY;
extern volatile unsigned char xdata CR;
extern volatile unsigned char xdata PAHSEL;
extern volatile unsigned char xdata PALSEL;
extern volatile unsigned char xdata PAPU;
extern volatile unsigned char xdata PAPD;
extern volatile unsigned char xdata PAOD;
extern volatile unsigned char xdata PAINEN;
extern volatile unsigned char xdata PAIPEN;
extern volatile unsigned char xdata PASMT;
extern volatile unsigned char xdata PBHSEL;
extern volatile unsigned char xdata PBLSEL;
extern volatile unsigned char xdata PBPU;
extern volatile unsigned char xdata PBPD;
extern volatile unsigned char xdata PBOD;
extern volatile unsigned char xdata PBINEN;
extern volatile unsigned char xdata PBIPEN;
extern volatile unsigned char xdata PBSMT;
extern volatile unsigned char xdata PCHSEL;
extern volatile unsigned char xdata PCLSEL;
extern volatile unsigned char xdata PCPU;
extern volatile unsigned char xdata PCPD;
extern volatile unsigned char xdata PCOD;
extern volatile unsigned char xdata PCINEN;
extern volatile unsigned char xdata PCIPEN;
extern volatile unsigned char xdata PCSMT;
extern volatile unsigned char xdata PDHSEL;
extern volatile unsigned char xdata PDLSEL;
extern volatile unsigned char xdata PDPU;
extern volatile unsigned char xdata PDPD;
extern volatile unsigned char xdata PDOD;
extern volatile unsigned char xdata PDINEN;
extern volatile unsigned char xdata PDIPEN;
extern volatile unsigned char xdata PDSMT;
extern volatile unsigned char xdata PIT;
extern volatile unsigned char xdata PAIF;
extern volatile unsigned char xdata PBIF;
extern volatile unsigned char xdata PCIF;
extern volatile unsigned char xdata PDIF;
extern volatile unsigned char xdata PADR;
extern volatile unsigned char xdata PASR;
extern volatile unsigned char xdata PBDR;
extern volatile unsigned char xdata PBSR;
extern volatile unsigned char xdata PCDR;
extern volatile unsigned char xdata PCSR;
extern volatile unsigned char xdata PDDR;
extern volatile unsigned char xdata PDSR;
extern volatile unsigned char xdata ADCON0;
extern volatile unsigned char xdata ADCON1;
extern volatile unsigned char xdata ADCON2;
extern volatile unsigned char xdata ADCDLY;
extern volatile unsigned char xdata ADCRH;
extern volatile unsigned char xdata ADCRL;
extern volatile unsigned char xdata ADCMPH;
extern volatile unsigned char xdata ADCMPL;
extern volatile unsigned char xdata ADCINT;
extern volatile unsigned char xdata ADCCHCON;
extern volatile unsigned char xdata DPDMC0;
extern volatile unsigned char xdata DPDMC1;
extern volatile unsigned char xdata BMCCON;
extern volatile unsigned char xdata BMCENC;
extern volatile unsigned char xdata BMCENCF;
extern volatile unsigned char xdata BMCDEC;
extern volatile unsigned char xdata BMCDECTH;
extern volatile unsigned char xdata TM2CR;
extern volatile unsigned char xdata TM2CCMR;
extern volatile unsigned char xdata TM2CCTR;
extern volatile unsigned char xdata TM2OCR;
extern volatile unsigned char xdata TM2EGR;
extern volatile unsigned char xdata TM2SR;
extern volatile unsigned char xdata TM2IER;
extern volatile unsigned char xdata TM2CNTH;
extern volatile unsigned char xdata TM2CNTL;
extern volatile unsigned char xdata TM2ARRH;
extern volatile unsigned char xdata TM2ARRL;
extern volatile unsigned char xdata TM2CCRH;
extern volatile unsigned char xdata TM2CCRL;
extern volatile unsigned char xdata TM2DTG;
extern volatile unsigned char xdata TM3CR;
extern volatile unsigned char xdata TM3CCMR;
extern volatile unsigned char xdata TM3CCTR;
extern volatile unsigned char xdata TM3OCR;
extern volatile unsigned char xdata TM3EGR;
extern volatile unsigned char xdata TM3SR;
extern volatile unsigned char xdata TM3IER;
extern volatile unsigned char xdata TM3CNTH;
extern volatile unsigned char xdata TM3CNTL;
extern volatile unsigned char xdata TM3ARRH;
extern volatile unsigned char xdata TM3ARRL;
extern volatile unsigned char xdata TM3CCRH;
extern volatile unsigned char xdata TM3CCRL;
extern volatile unsigned char xdata TM3DTG;
extern volatile unsigned char xdata TM4CR;
extern volatile unsigned char xdata TM4CCMR;
extern volatile unsigned char xdata TM4CCTR;
extern volatile unsigned char xdata TM4OCR;
extern volatile unsigned char xdata TM4EGR;
extern volatile unsigned char xdata TM4SR;
extern volatile unsigned char xdata TM4IER;
extern volatile unsigned char xdata TM4CNTH;
extern volatile unsigned char xdata TM4CNTL;
extern volatile unsigned char xdata TM4ARRH;
extern volatile unsigned char xdata TM4ARRL;
extern volatile unsigned char xdata TM4CCRH;
extern volatile unsigned char xdata TM4CCRL;
extern volatile unsigned char xdata TM4DTG;
extern volatile unsigned char xdata PWMCON0;
extern volatile unsigned char xdata PWMCON1;
extern volatile unsigned char xdata PWMPL;
extern volatile unsigned char xdata PWMPH;
extern volatile unsigned char xdata PWM0DUL;
extern volatile unsigned char xdata PWM0DUH;
extern volatile unsigned char xdata PWM1DUL;
extern volatile unsigned char xdata PWM1DUH;
extern volatile unsigned char xdata PWM2DUL;
extern volatile unsigned char xdata PWM2DUH;
extern volatile unsigned char xdata PWM3DUL;
extern volatile unsigned char xdata PWM3DUH;
extern volatile unsigned char xdata PWM4DUL;
extern volatile unsigned char xdata PWM4DUH;
extern volatile unsigned char xdata PWM5DUL;
extern volatile unsigned char xdata PWM5DUH;
extern volatile unsigned char xdata PWMDTC;
extern volatile unsigned char xdata PWMDTL;
extern volatile unsigned char xdata PWMDTH;
extern volatile unsigned char xdata PWMPOL;
extern volatile unsigned char xdata PWMOEN;
extern volatile unsigned char xdata PWMMD;
extern volatile unsigned char xdata PWMFBK0;
extern volatile unsigned char xdata PWMFBK1;
extern volatile unsigned char xdata PWMINTC;
extern volatile unsigned char xdata PWMPFRAC;
extern volatile unsigned char xdata PWMDFRACL;
extern volatile unsigned char xdata PWMDFRACH;
extern volatile unsigned char xdata LEDCTR;
extern volatile unsigned char xdata LEDSTAT;
extern volatile unsigned char xdata LEDICLR;
extern volatile unsigned char xdata LED0DATA;
extern volatile unsigned char xdata LED0T0L;
extern volatile unsigned char xdata LED0T0H;
extern volatile unsigned char xdata LED1DATA;
extern volatile unsigned char xdata LED1T0L;
extern volatile unsigned char xdata LED1T0H;

#ifndef uint8_t
#define uint8_t unsigned char
#endif  // uint8_t

#ifndef uint16_t
#define uint16_t unsigned int
#endif  // uint16_t

#ifndef uint32_t
#define uint32_t unsigned long
#endif  // uint32_t


#endif /* __LNM8F01_H__ */
